<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta http-equiv="pragram" content="no-cache">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>[title]</title>
    <link href="/Public/Home/css/style.css" rel="stylesheet" type="text/css">
    <link href="/Public/Home/css/iconfont.css" rel="stylesheet" type="text/css">
    <script src="/Public/Home/js/jquery-1.11.1.min.js"></script>
    <script src="/Public/Home/js/publicjquery.js"></script>
    <script src="/Public/Home/js/layer/layer.js" ></script>
    <script src="/Public/Home/js/common.js" ></script>
    <script src="/Public/Home/js/ajaxfileupload.js" ></script>
</head>
<body onselectstart="return false">
<div class="main FromUpToDown" >
    <div class="content" style="position: relative">
        <div class="head-content">
            <div class="head-title">
                <span><?php echo ACTION_NAME == 'edit' ? '修改' : '添加';?>取件</span>
            </div>
        </div>
        <form action='' id="form" >
            <div class="form-content">
			 <div class="form">
                    <div class="form-left">货柜编号</div>
                    <div class="form-right">
                        <select class="form-input-small" name="container_id" id="">
                        <?php if(is_array($container)): foreach($container as $key=>$vo): if(ACTION_NAME == 'add'): ?><option <?php echo session('container_id') == $vo['id'] ? 'selected' : '';?> value="<?php echo ($vo['id']); ?>"><?php echo ($vo['no']); ?></option>
                                <?php else: ?>
                                <option <?php echo $info['container_id'] == $vo['id'] ? 'selected' : '';?> value="<?php echo ($vo['id']); ?>"><?php echo ($vo['no']); ?></option><?php endif; endforeach; endif; ?>
                        </select>
                    </div>
                </div>
                <div class="form">
                    <div class="form-left">快件编号</div>
                    <div class="form-right">
                        <input class="form-input-small" type="text" name='no'  value="<?php echo ($info['no']); ?>" placeholder="快件编号"  />
                    </div>
                </div>              
                <div class="form">
                    <div class="form-left">取件人号码</div>
                    <div class="form-right">
                        <input class="form-input-small" type="text" name='phone'  value="<?php echo ($info['phone']); ?>" placeholder="收件人号码"  />
                    </div>
                </div>
                <div class="form">
                    <div class="form-left">取件人姓名</div>
                    <div class="form-right">
                        <input class="form-input-small" type="text" name='name'  value="<?php echo ($info['name']); ?>" placeholder="取件人姓名"  />
                    </div>
                </div>
                <div class="form">
                    <div class="form-left">收件人地址</div>
                    <div class="form-right">
                        <textarea  name="addr" cols="30" rows="6"><?php echo ($info['addr']); ?></textarea>
                    </div>
                </div>

                <input type='hidden' name='id' value="<?php echo ($info['id']); ?>" >
                <div class="form-operate">
                    <button type='button' id="save"  class="form-button color-bg-green">保存</button>
                    <button type='button' onclick="history.go(-1)" class="form-button color-bg-grey">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="main-foot">Copyright  2013-2015 WeiGouTong.com. All Rights Reserved.  苏ICP备09098830号</div>
<script>
    $("input[name='no']").focus();
    $("#save").click(function(){

        if($("input[name='no']").val() == ''){
            layer.tips('请输入快件编号！', 'input[name="no"]', {tips: [2, 'red'], time: 1000});
            return;
        }
        
        var reg = /^1[34578]\d{9}$/;
        if(!reg.test($("input[name='phone']").val())){
            layer.tips('请输入正确手机号！', 'input[name="phone"]', {tips: [2, 'red'], time: 1000});
            return;
        }
		if($("input[name='name']").val() == ''){
            layer.tips('请输入取件人姓名！', 'input[name="name"]', {tips: [2, 'red'], time: 1000});
            return;
        }
        $("#save").attr('disabled',true);
        $.post(
                "<?php echo U('save');?>",
                $("#form").serialize(),
                function(res){
                    if(res.status == 1){
                        layer.tips(res.info, '#save', {tips: [2, 'green'], time: 1000});
                        setTimeout("location.href = '<?php echo U('add');?>'",1000);
                    }else{
                        $("#save").attr('disabled',false);
						if(res.info == '快递号重复'){
						layer.tips(res.info, 'input[name="no"]', {tips: [2, 'red'], time: 1000});
						return;
						}
                        layer.tips(res.info, '#save', {tips: [2, 'red'], time: 1000});
                    }
                }
        );
    });

    $("input[name='phone']").bind("input propertychange",function(){
            var reg = /^1[34578]\d{9}$/;
            var phone = $(this).val();
            if(reg.test($(this).val())){
                $.post(
                        "<?php echo U('Customer/getName');?>",
                        {
                            phone:phone
                        },function(res){
                           if(res.status == 1){
                               $("input[name='name']").val(res.info);
                           }
                        }
                );
            }
    })
	
	$("form input").keydown(function(e){		     
    if (e.which == 13) {// 判断所按是否回车键  
        var inputs = $("form").find(":text"); // 获取表单中的所有输入框  
        var idx = inputs.index(this); // 获取当前焦点输入框所处的位置  
        if (idx == inputs.length - 1) {// 判断是否是最后一个输入框               
            $("#save").click(); // 提交表单  
        } else {  
            inputs[idx + 1].focus(); // 设置焦点  
            inputs[idx + 1].select(); // 选中文字  
        }  
        return false;// 取消默认的提交行为  
    }  
	});
</script>
</body>
</html>